package com.baijiayun.liveuibase.widgets.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.view.ViewGroup;
import android.view.Window;

import com.baijiayun.liveuibase.utils.DisplayUtils;
import com.baijiayun.liveuibase.widgets.GaussianBlurView;

/**
 * Created by Shubo on 2018/9/21.
 */
public class BaseDialog extends Dialog {

    public BaseDialog(@NonNull Context context) {
        super(context, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
    }

    public BaseDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }

    public BaseDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Window window = getWindow();
        if (window == null) return;

        DisplayUtils.hideBottomUIMenu(window);

        GaussianBlurView gaussianBlurView = new GaussianBlurView(getContext());

        ViewGroup viewGroup = (ViewGroup) window.getDecorView().getRootView();
        viewGroup.addView(gaussianBlurView);
        viewGroup.getChildAt(0).bringToFront();
    }

    @Override
    public void dismiss() {
        try {
            super.dismiss();
        } catch (Exception ignore){
            // do nothing
        }
    }
}
